package com.yunban.project.message.controller;

import cn.hutool.core.util.RandomUtil;
import com.yunban.project.message.dto.SmsSendReq;
import com.yunban.project.message.service.SmsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import net.lab1024.sa.base.common.annoation.NoNeedLogin;
import net.lab1024.sa.base.module.support.operatelog.annotation.OperateLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author: lijiajun
 * @date: 2025-03-07
 * @version: 1.0
 */
@OperateLog
@RestController
@Tag(name = "短信服务")
@RequestMapping("/sms-api")
public class SmsController {

    @Resource
    private SmsService smsService;

    @NoNeedLogin
    @PostMapping("/send/sms/code")
    @Operation(summary = "发送短信验证码")
    Boolean sendSmsCode(@RequestBody @Validated SmsSendReq req) {
        // 获取5位随机数
        String code = RandomUtil.randomNumbers(5);
        return this.smsService.send(code, req.getPhoneNo());
    }
}